package ulmermark.demo.rest.spring;

import java.util.Collection;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class OrdersController {
    
    @Autowired
    private OrdersService ordersService;

    @RequestMapping("/orders/{orderId}")
    public ModelAndView  findOrder(@PathVariable String orderId, final Model model) {
      Order order  = ordersService.get(orderId);  
      ModelAndView mav = new ModelAndView("orders-show", "order", order);
      return mav;
    }
    @RequestMapping("/orders/")
    public ModelAndView findAllOrders(final Model model) {
      List<Order> orders  = ordersService.getAll();
      ModelAndView mav = new ModelAndView("orders-index", "orders", orders);
      return mav;
    }

}
